package com.zego.wawaji.ui.center.user;

import android.content.Context;
import android.content.res.Resources;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zego.wawaji.R;
import com.zego.wawaji.ui.UIShow;
import com.zego.wawaji.ui.base.BasePanel;
import com.zego.wawaji.ui.base.recycler.BaseRecyclerViewHolder;
import com.zego.wawaji.ui.dialog.PickerDialogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 个人中心Foot
 */
public class UserCenterFoot extends BasePanel implements BaseRecyclerViewHolder.OnItemClickListener {
    private RecyclerView recyclerView;
    private UserAuthAdapter userAuthAdapter;

    public UserCenterFoot(Context context) {
        super(context);
        setContentView(R.layout.user_center_foot);
        initData();
    }

    // 初始化条目数据
    private void initData() {
        List<UserAuth> userAuthList = new ArrayList<>();
        Resources resources = getContext().getResources();
        recyclerView = (RecyclerView) findViewById(R.id.user_fragment_footer);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setNestedScrollingEnabled(false); // 嵌套ScrollView滑动惯性消失
        String[] names = resources.getStringArray(R.array.user_authority_name);
        int[] levels = resources.getIntArray(R.array.user_authority_level);
        int[] icons = new int[]{R.drawable.coin_gold, R.drawable.coin_ico, R.drawable.user_ico09, R.drawable.user_ico04, R.drawable.user_ico03, R.drawable.user_ico02, R.drawable.user_ico05, R.drawable.user_ico07, R.drawable.user_ico08};

        for (int i = 0; i < names.length; i++) {
            UserAuth userAuth = new UserAuth(i, icons[i], levels[i], names[i], isShow(i));
            userAuthList.add(userAuth);
        }
        userAuthAdapter = new UserAuthAdapter();
        userAuthAdapter.setList(userAuthList);
        recyclerView.setAdapter(userAuthAdapter);
        userAuthAdapter.setOnItemClickListener(this);
    }

    /**
     * 刷新list
     */
    public void refreshView() {
        userAuthAdapter.notifyDataSetChanged();
    }

    /**
     * 判断指定条目显隐状态
     */
    private boolean isShow(int id) {
        if (id == CenterItemID.i_Center_item_7
                || id == CenterItemID.i_Center_item_6
                || id == CenterItemID.i_Center_item_3) {
            return false;
        }
        return true;
    }

    @Override
    public void onItemClick(View convertView, int position) {
        switch (position) {
            case CenterItemID.i_Center_item_1: // 我的金币
//                UIShow.showMyPropertyAct(getActivity());
                PickerDialogUtil.showPayDialog((FragmentActivity) getActivity());
                break;

            case CenterItemID.i_Center_item_2: // 我的娃娃币
                UIShow.showInviteAct(getActivity());
                break;

            case CenterItemID.i_Center_item_3:// 我的积分
                break;

            case CenterItemID.i_Center_item_4:// 账单明细
                UIShow.showMyCreditAct(getActivity());
                break;

            case CenterItemID.i_Center_item_5:// 我的娃娃
                UIShow.showMyBillAct(getActivity());
                break;

            case CenterItemID.i_Center_item_6:// 邀请好友
                break;

            case CenterItemID.i_Center_item_7:// 设置
                UIShow.showInviteAct(getActivity());
                break;

            case CenterItemID.i_Center_item_8: // 关于我们
                UIShow.showSettingAct(getActivity());
                break;

            case CenterItemID.i_Center_item_9:
                UIShow.showAboutAct(getActivity());
                break;
        }
    }
}
